
$(document).ready(function(){
	$('input[type="text"]').each(function(){
		if(this.id != 'userid'){
			$(this).attr('disabled', 'true');
		}
	});
	$('select').each(function(){
		$(this).attr('disabled', 'true');
	});
	
	$("#btnsearch").bind("click", function() {
		var v = $('#userid').val();
		if(v == ''){
			alert('Please enter UID.');
			return;
		}
		$.ajax({type:"POST", 
			url:'loadWHV.php',
			data:{userid: v}, 
			success:function (msg) {
				var res = eval('(' + msg + ')');
				if(res.errorMsg){
					alert(res.errorMsg);
					return;
				}
				$('input[type="text"]').each(function(){$(this).removeAttr('disabled');});
				$('select').each(function(){$(this).removeAttr('disabled');});
				for(var key in res){
					$('#' + key).val(res[key]);
				}
		}});
	});
	
	$("#btncreate").bind("click", function() {
		$('input[type="text"]').each(function(){
			$(this).removeAttr('disabled');
			$(this).val('');
		});
		
		$('select').each(function(){
			$(this).removeAttr('disabled');
		});
	});
	
	$("#btnsave").bind("click", function() {
		var v = $('#userid').val();
		if(v == ''){
			alert('Please enter UID.');
			return;
		}
		$.ajax({type:"POST", 
			url:'saveWHV.php',
			data:$('#userform').serialize(), 
			success:function (msg) {
				if(msg == 'success'){
					alert('Save success.');
				}
		}});
	});
});

